package changqin.disruptor.spider;

import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
import org.apache.http.impl.nio.client.HttpAsyncClients;
import org.apache.http.util.EntityUtils;

public class GetSample {
	
	public static final String	DEFAULT_ENCODE				= "UTF-8";
	public static final String	DEFAULT_HTTP_CONTENT_TYPE	= "application/json;charset=UTF-8";
	java.util.logging.Logger logger = java.util.logging.Logger
			.getLogger("");
	public static void main(String[] args) {
		try {
			CloseableHttpAsyncClient httpClient;
			httpClient = HttpAsyncClients.createDefault();
			httpClient.start();
	
			String url = "http://www.doupocangqiong1.com/1/1.html?url=http://www.dpcq1.com/dpcq/1973852.json";
			HttpPost request = new HttpPost(url);
			String content = "";
			request.setEntity(new ByteArrayEntity(content
					.getBytes(DEFAULT_ENCODE)));
	
			request.setHeader("Content-Type",
					DEFAULT_HTTP_CONTENT_TYPE);
	
			Future<HttpResponse> future = httpClient.execute(request, null);
			HttpResponse response = future.get(60, TimeUnit.SECONDS);
	
			System.out.println(EntityUtils.toString(response.getEntity()));
		} catch (IOException e) {
			// 发生网络异常
			e.printStackTrace();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ExecutionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (TimeoutException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			// 释放连接 （一定要记住）
		}
	}
}